<template>
  <div>
      <h1></h1>
    <van-row>
        
        <van-col span="3"> <celan/> </van-col>
        <van-col span="20"> <sellheader/> 
        <div style="padding-left: 0px;">
            <van-row>
          <van-col span="6">
            <van-button type="info" @click="add_show">新增</van-button>
          </van-col>
          <van-col span="6">
            <van-button disabled type="primary" @click="exporta">导出</van-button>
          </van-col>
          <van-col span="6">
            <van-uploader :after-read="afterRead" multiple accept=".xls">导入</van-uploader>
          </van-col>
        </van-row>
            <repl @chagepid="getpid"/>
            <van-field label="组织名称" v-model="name"/>
            <van-field label="组织编号" v-model="coding"/>
            <van-radio-group v-model="type">
              <van-radio name="1">公司 1</van-radio>
              <van-radio name="2">部门 2</van-radio>
            </van-radio-group>
            <van-field label="组织排序" v-model="num"/>
            <van-button @click="add">添加</van-button>
        </div>
        </van-col>
    </van-row>
  </div>
</template>

<script>
import myaxios from "axios";
import sellheader from './sellheader.vue'
import celan from './celan_zi.vue'
import repl from './repl_zi.vue'
export default {
    components:{
        sellheader,
        celan,
        repl
    },
    data() {
    return {
        pid:0,
        type:1,
        name:'',
        coding:'',
        num:0
    }
  },
  methods: {
    handleNodeClick(list) {
      console.log(list)
    },
    afterRead(file){
      let formdate = new FormData()
      formdate.append('file',file.file)
      console.log(formdate)
      myaxios({url:'http://127.0.0.1:5000/upload',method:'post',data:formdate}).then(res=>{
        alert(res.data.msg)
      })
    },
    exporta(){
      myaxios({url:'http://127.0.0.1:5000/download',method:'get'}).then(res=>{
        console.log(res)
      })
    },
    add(){
      if(localStorage.getItem('pid')){
        this.pid = localStorage.getItem('pid')
      }
      let date = {'name': this.name, 'coding': this.coding, 'type':this.type, 'num': this.num, 'pid': this.pid}
      myaxios({url:'http://127.0.0.1:5000/create', method:'post', data:date}).then(res=>{
        console.log(res)
      })
    }
  },



}
</script>

<style>

</style>